var city = require('../../utils/city.js');
var database = require('../../data/data.js')
var app = getApp()
Page({
  data: {
    searchLetter: [],
    showLetter: "",
    winHeight: 0,
    // tHeight: 0,
    // bHeight: 0,
    cityList: [],
    isShowLetter: false,
    scrollTop: 0,//置顶高度
    scrollTopId: '',//置顶id
    city: "",
    hotcityList: [{ cityCode: 110000, city: '北京' }, { cityCode: 310000, city: '上海' }, { cityCode: 440100, city: '广州' }, { cityCode: 440300, city: '深圳' }, { cityCode: 330100, city: '杭州' }, { cityCode: 320100, city: '南京' }, { cityCode: 420100, city: '武汉' }, { cityCode: 410100, city: '郑州' }, { cityCode: 120000, city: '天津' }, { cityCode: 610100, city: '西安' }, { cityCode: 510100, city: '成都' }, { cityCode: 500000, city: '重庆' }]
  },
  onLoad: function (options) {
    // 生命周期函数--监听页面加载
    var searchLetter = city.searchLetter;
    var cityList = city.cityList();
    var sysInfo = wx.getSystemInfoSync();
    var winHeight = sysInfo.windowHeight;
    var itemH = winHeight / searchLetter.length;
    var tempObj = [];
    for (var i = 0; i < searchLetter.length; i++) {
      var temp = {};
      temp.name = searchLetter[i];
      temp.tHeight = i * itemH;
      temp.bHeight = (i + 1) * itemH;
      tempObj.push(temp)
    }
    this.setData({
      winHeight: winHeight,
      itemH: itemH,
      searchLetter: tempObj,
      cityList: cityList,
      city:options.city
    })

  },
  clickLetter: function (e) {
    var showLetter = e.currentTarget.dataset.letter;
    this.setData({
      showLetter: showLetter,
      isShowLetter: true,
      scrollTopId: showLetter,
    })
    var that = this;
    setTimeout(function () {
      that.setData({
        isShowLetter: false
      })
    }, 1000)
  },
  bindCity: function (e) {
    var city = e.currentTarget.dataset.city
    var count = city.indexOf("市")
    if (count > 0) {
      city = city.substring(0, city.length - 1);
    }
    this.setData({ city: city })
    database.city = city
    wx.reLaunch({
      url: '../home/home?city=' + city,
    })
  },
  bindHotCity: function (e) {
    this.setData({ city: e.currentTarget.dataset.city })
    database.city = city
    wx.reLaunch({
      url: '../home/home?city=' + e.currentTarget.dataset.city,
    })
  },
  hotCity: function () {
    this.setData({
      scrollTop: 0,
    })
  }
})